package com.hunlian.makelove.update;

import org.json.JSONException;
import org.json.JSONObject;



public class AppUpdateParser {
	
	public AppUpdate parse(String jsonStr) throws WebServiceError {
		if (jsonStr == null) {
			return null;
		}
		AppUpdate appUpdate = new AppUpdate();
		try {
			JSONObject obj = new JSONObject(jsonStr);
			boolean result = obj.getBoolean("result");
			if (result == false) {
				return null;
			}
			if (obj.has("type")) {
				appUpdate.setType(obj.getString("type"));
			}
			if (obj.has("version")) {
				appUpdate.setVersion(obj.getString("version"));
			}
			if (obj.has("force_version")) {
				appUpdate.setForceVersion(obj.getString("force_version"));
			}
			if (obj.has("download_url")) {
				appUpdate.setDownloadUrl(obj.getString("download_url"));
			}
			if (obj.has("log")) {
				appUpdate.setLog(obj.getString("log"));
			}
			
		} catch (JSONException e) {
			e.printStackTrace();
			//throw new WebServiceError(ConstantData.JSON_ERROR_TOAST);//e.getLocalizedMessage()
		}
		return appUpdate;
	}
}
